---
title: "Identifying Price Informativeness"
author: "Eduardo Davila^[Yale] & Cecilia Parlatore^[NYU Stern]"
date: "`r Sys.Date()`"
output:
  html_document: default
  pdf_document: default
---

```{r echo=FALSE, include=FALSE}

library(here); library(tidyverse); library(foreach); library(doParallel); library(AER)
path <- here::here(); print(path); setwd(path); rm(path)

source("functions/fn_remove_outliers.R")

load("intermediate/results_rolling.RData")
load("intermediate/parameters.RData")

```

```{r}
  
results_q_rolling_outlier <- remove_outliers(results_q_rolling, 0.95)
results_q_rolling_unlearnable_outlier <- remove_outliers(results_q_rolling_unlearnable, 0.95)
results_q_rolling_nocon_outlier <- remove_outliers(results_q_rolling_nocon, 0.95)

results_q_rolling_clean <- results_q_rolling_outlier %>%
  mutate(datefrac_start = year_start + month_start/12,
         datefrac_end   = year_end   + month_end/12, 
         date_diff      = datefrac_end - datefrac_start) %>% 
  filter(date_diff == N_q/4 - 0.25)

results_q_rolling_unlearnable_clean <- results_q_rolling_unlearnable_outlier %>%
  mutate(datefrac_start = year_start + month_start/12,
         datefrac_end   = year_end   + month_end/12, 
         date_diff      = datefrac_end - datefrac_start) %>% 
  filter(date_diff == N_q/4 - 0.25)

results_q_rolling_nocon_clean <- results_q_rolling_nocon_outlier %>%
  mutate(datefrac_start = year_start + month_start/12,
         datefrac_end   = year_end   + month_end/12, 
         date_diff      = datefrac_end - datefrac_start) %>% 
  filter(date_diff == N_q/4 - 0.25)

results_q_rolling_tenor_clean <- c()
for(current_tenor in tenors){
  df <- results_q_rolling_tenor %>% filter(tenor == current_tenor)
  df <- remove_outliers(df, 0.95)
  df <- df %>%
    mutate(datefrac_start = year_start + month_start/12,
           datefrac_end   = year_end   + month_end/12, 
           date_diff      = datefrac_end - datefrac_start) %>% 
    filter(date_diff == N_q/4 - 0.25)
  
  results_q_rolling_tenor_clean <- rbind(results_q_rolling_tenor_clean, df)
}

save(results_q_rolling_clean, results_q_rolling_unlearnable_clean, results_q_rolling_tenor_clean, results_q_rolling_nocon_clean, file = paste0("intermediate/results_rolling_clean.RData"))

```
